<?php



class Model_DbTable_Order_Shipmentdetail extends Zend_Db_Table_Abstract {

	protected $_name = 'orders_shipment_detail';
	/**
	 *  Get Shipment Detail By ID
	 * @param int $idOrder
	 */
	public function getShipmentdetail( $idOrder){
		
		$row = $this->fetchRow("`id_order` = ". $idOrder);
		if(!$row) return false;
		return $row->toArray();		
		
		}
	/**
	 * Add Shipment Detail , when Add tracking No in the list order summary 
	 * @param unknown_type $noOrder
	 * @param unknown_type $shopCode
	 * @param unknown_type $dateOrder
	 * @param unknown_type $staffOrder
	 * @param unknown_type $codeProduct
	 * @param unknown_type $desProduct
	 * @param unknown_type $qtyOrder
	 * @param unknown_type $statusHot
	 * @param unknown_type $shipmentNo
	 * @param unknown_type $chinaSend
	 * @param unknown_type $auReceived
	 * @param unknown_type $dateReceived
	 * @param unknown_type $isExtra
	 * @param unknown_type $idSupplier
	 * @param unknown_type $boxNo
	 */	
	public function addShipmentdetail( $noOrder , $shopCode , $dateOrder , $staffOrder , $codeProduct , $desProduct , $qtyOrder , $statusHot , $shipmentNo , $chinaSend , $auReceived , $dateReceived , $isExtra , $idSupplier , $boxNo){
		
		$data = array(
			
         "no_order" =>  $noOrder ,
         "shop_code" =>  $shopCode ,
         "date_order" =>  $dateOrder ,
         "staff_order" =>  $staffOrder ,
         "code_product" =>  $codeProduct ,
         "des_product" =>  $desProduct ,
         "qty_order" =>  $qtyOrder ,
         "status_hot" =>  $statusHot ,
         "shipment_no" =>  $shipmentNo ,
         "china_send" =>  $chinaSend ,
         "au_received" =>  $auReceived ,
         "date_received" =>  $dateReceived ,
         "is_extra" =>  $isExtra ,
         "id_supplier" =>  $idSupplier ,
         "box_no" =>  $boxNo 
	
			);
		$this->insert($data);
		
		}
	/**
	 * No use function , update detail
	 * @param unknown_type $idOrder
	 * @param unknown_type $noOrder
	 * @param unknown_type $shopCode
	 * @param unknown_type $dateOrder
	 * @param unknown_type $staffOrder
	 * @param unknown_type $codeProduct
	 * @param unknown_type $desProduct
	 * @param unknown_type $qtyOrder
	 * @param unknown_type $statusHot
	 * @param unknown_type $shipmentNo
	 * @param unknown_type $chinaSend
	 * @param unknown_type $auReceived
	 * @param unknown_type $dateReceived
	 * @param unknown_type $isExtra
	 * @param unknown_type $idSupplier
	 * @param unknown_type $boxNo
	 */	
	public function updateShipmentdetail(  $idOrder ,  $noOrder , $shopCode , $dateOrder , $staffOrder , $codeProduct , $desProduct , $qtyOrder , $statusHot , $shipmentNo , $chinaSend , $auReceived , $dateReceived , $isExtra , $idSupplier , $boxNo){
		$data = array(
			
         "no_order" =>  $noOrder ,
         "shop_code" =>  $shopCode ,
         "date_order" =>  $dateOrder ,
         "staff_order" =>  $staffOrder ,
         "code_product" =>  $codeProduct ,
         "des_product" =>  $desProduct ,
         "qty_order" =>  $qtyOrder ,
         "status_hot" =>  $statusHot ,
         "shipment_no" =>  $shipmentNo ,
         "china_send" =>  $chinaSend ,
         "au_received" =>  $auReceived ,
         "date_received" =>  $dateReceived ,
         "is_extra" =>  $isExtra ,
         "id_supplier" =>  $idSupplier ,
         "box_no" =>  $boxNo 
	
			);
			
		$this->update($data,"`id_order` = ". $idOrder);
		}
	/**
	 * no use function , remove line of shipment detail 
	 * @param unknown_type $idOrder
	 */	
	public function deleteShipmentdetail( $idOrder){
		
		$this->delete("`id_order` = ". $idOrder);
		
		}	
	/**
	 * no use function , list all shipment 
	 */
	public function listAll(){
		
		$rows =$this->fetchAll("1","id_order DESC ");
		if(!$rows) return false;
		return $rows->toArray();			
		
		}
	public function orderNoInShipment($shipmentNo){
		$select = $this->_db->select()
							->distinct()	
							->from($this->_name,array('no_order'))
							->where("`shipment_no` LIKE '{$shipmentNo}'")
							->order('no_order');
		return $this->getAdapter()->fetchAll($select);
	}
	
	public function getShipmentByNo($shipmentNo){
		
		$whereStr = "`shipment_no` LIKE '{$shipmentNo}'";
		$rows = $this->fetchAll($whereStr)->toArray();
		
		if(!(boolean)$rows) return false;
		
		return $rows;
		
	}		
	
	/**
	 * Get all shipment detail by orderNo
	 * @author Leo
	 * @param unknown_type $orderNo
	 */
	public function getShipmentByOrderNo($orderNo){
	
		$whereStr = "`no_order` LIKE '{$orderNo}'";
		$rows = $this->fetchAll($whereStr)->toArray();
	
		if(!(boolean)$rows) return false;
	
		return $rows;
	
	}
	
	/**
	 * Update shipment no.
	 * @author Leo
	 * @param unknown_type $idOrder
	 * @param unknown_type $shipmentNo
	 */
	public function updateShipmentNo(  $idOrder , $shipmentNo){
		$data = array(
				"shipment_no" =>  $shipmentNo ,
	
		);
			
		$this->update($data,"`id_order` = ". $idOrder);
	}
	
}


?>